<template>
	<view class="container">
		
		<view class="tui-dropdown-box text-center">
			<image :src="logo" mode="heightFix" class="logo"></image>
		</view>
		
		<view class="tui-form">
			<view class="tui-view-input">
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
					<view class="tui-cell-input tui-my-input">
						<iconfont className="icon-renwu1 padding" color="#6d7a87" :size="20"></iconfont>
						<input  placeholder="用户名" placeholder-class="tui-phcolor" type="text" maxlength="11" v-model="username"/>
						<view class="tui-icon-close1" v-show="mobile" @tap="clearInput(1)">
							<iconfont className="icon-cuowu1" :size="16" color="#bfbfbf"></iconfont>
						</view>
					</view>
				</tui-list-cell>
				
				<tui-list-cell :hover="false" :lineLeft="false"  backgroundColor="transparent">
					<view class="tui-cell-input tui-my-input">
						<iconfont className="icon-aui-icon-mobile padding" color="#6d7a87" :size="20"></iconfont>
						<input :value="mobile" placeholder="请输入手机号" placeholder-class="tui-phcolor" type="number" maxlength="11" @input="inputMobile" />
						<view class="tui-icon-close1" v-show="mobile" @tap="clearInput(1)">
							<iconfont className="icon-cuowu1" :size="16" color="#bfbfbf"></iconfont>
						</view>
					</view>
				</tui-list-cell>
				
				
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent" v-if="usecode">
					<view class="tui-cell-input tui-my-input">
						<iconfont className="icon-mima padding" color="#6d7a87" :size="20"></iconfont>
						<input placeholder="请输入验证码" placeholder-class="tui-phcolor" type="text" maxlength="6" @input="inputCode" />
						<view class="tui-btn-send" :class="{ 'tui-gray': isSend }" :hover-class="isSend ? '' : 'tui-opcity'" :hover-stay-time="150" @tap="sendCode">{{ btnSendText }}</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
					<view class="tui-cell-input tui-my-input">
						<iconfont className="icon-mima padding" color="#6d7a87" :size="20"></iconfont>
						<input :value="password" placeholder="请输入密码" :password="true" placeholder-class="tui-phcolor" type="text" maxlength="40" @input="inputPwd" />
						<view class="tui-icon-close1" v-show="password" @tap="clearInput(2)">
							<iconfont className="icon-cuowu1" :size="16" color="#bfbfbf"></iconfont>
						</view>
					</view>
				</tui-list-cell>
			</view>
			<view class="padding-lr">
				<view class="tui-btn-box" @tap="register">
					<tui-button :disabledGray="true" type="danger"  :shadow="true" shape="circle">注册</tui-button>
				</view>
			</view>
			<view class="padding-lr">
				<view class="tui-flex tui-cell-text">
					<view class="tui-col-8">
						<view class="tui-color-black" hover-class="tui-opcity" :hover-stay-time="150" @tap="protocol">用户注册协议</view>
					</view>
					<view class="tui-col-4">
						<view class="tui-color-black text-right" hover-class="tui-opcity" :hover-stay-time="150" @tap="toLogin">已有账号</view>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			mobile: '',
			logo:'',
			password: '',
			username:'',
			code: '',
			usecode:true,
			isSend: false,
			btnSendText: '获取验证码' //倒计时格式：(60秒)
		};
	},
	onLoad() {
		let that = this
		console.log('邀请码全局存储',that.$store.state.inviteCode)
		that.tui.store().then((res)=>{
			that.logo = res.logo
			console.log('AAAAAAAAAA',res)
			console.log('关键词热搜',res.logo)
		}).catch((res)=>{
			console.log('shibai',res)
		});
	},
	methods: {
		register(){
			let that = this
			that.tui.request("/user/signup","POST",{
				username:that.username,
				mobile:that.mobile,
				password:that.password,
			}).then((res)=>{
				console.log(res)
				if (res.code == 200) {
					console.log(res)
					this.tui.toast(res.message);
					that.tui.href('/login')
				} else {
					this.tui.toast(res.message);
				}
			}).catch((res)=>{})
		},
		toLogin:function(){
			let that = this
			that.$Router.push({name:'login'})
		},
		back() {
			uni.navigateBack();
		},
		inputCode(e) {
			this.code = e.detail.value;
		},
		sendCode:function(){
			let that = this
			if(!that.iGlobal.isMobile(that.mobile)){
				this.tui.toast('请输入正确的手机号');
				return false;
			}
			that.tui.request("/user/sendcode","POST",{
				mobile:that.mobile,
				type:'register'
			}).then((res)=>{
				console.log(res)
				if (res.code == 200) {
					console.log(res)
					this.tui.toast(res.message);
				} else {
					this.tui.toast(res.message);
				}
			}).catch((res)=>{})
		},
		inputMobile: function(e) {
			this.mobile = e.detail.value;
		},
		inputPwd: function(e) {
			this.password = e.detail.value;
		},
		clearInput(type) {
			if (type == 1) {
				this.mobile = '';
			} else {
				this.password = '';
			}
		},
		protocol(){
			this.tui.href("/protocol")
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	.logo {
		width: 60%;
		height: 100px;
		border-radius: 10rpx;
		padding-top:20rpx;
	}
	.tui-page-title {
		width: 100%;
		font-size: 48rpx;
		font-weight: bold;
		color: $uni-text-color;
		line-height: 42rpx;
		padding: 110rpx 40rpx 40rpx 40rpx;
		box-sizing: border-box;
	}
	.tui-my-input{
		border: 1px solid rgb(109, 122, 135);
		border-radius: 50px;
		padding: 10px 0px!important;;
	}
	.tui-form {
		padding-top: 50rpx;
		.tui-view-input {
			width: 100%;
			box-sizing: border-box;
			padding: 0 40rpx;
			.tui-cell-input {
				width: 100%;
				display: flex;
				align-items: center;
				padding-top: 18.75rpx;
				padding-bottom: 18.75rpx;
				input {
					flex: 1;
					padding-left: $uni-spacing-row-base;
				}
				.tui-icon-close {
					margin-left: auto;
				}
				.tui-btn-send {
					width: 156rpx;
					text-align: right;
					flex-shrink: 0;
					font-size: $uni-font-size-base;
					color: $uni-color-primary;
					padding-right: 5px;
				}
				.tui-gray {
					color: $uni-text-color-placeholder;
				}
				.tui-icon-close1 {
					margin-left: auto;
					padding-right: 12.5rpx;
				}
			}
		}
		.tui-cell-text {
			width: 100%;
			padding: 40rpx $uni-spacing-row-lg;
			box-sizing: border-box;
			font-size: $uni-font-size-sm;
			color: $uni-text-color-grey;
			display: flex;
			align-items: center;
			.tui-color-primary {
				color: $uni-color-primary;
				padding-left: $uni-spacing-row-sm;
			}
		}
		.tui-btn-box {
			width: 100%;
			padding: 0 $uni-spacing-row-lg;
			box-sizing: border-box;
			margin-top: 80rpx;
		}
	}
}
</style>
